import "."
import "components"

import QtQuick 2.3
import whandgo 1.0

Item
{
    id: window

    width: 360
    height: 640

    /* inital state */
    state: "loading"

    /* object access */
    property alias theme: _theme
    property alias model: _model

    /* theme object */
    Theme { id: _theme }

    /* the app model object */
    AppModel
    {
        id: _model
        onReadyChanged:
        {
            if(_model.ready)
                window.state = "ready"
            else
                window.state = "loading"
        }
    }

    /* state changes */
    states:
    [
        State
        {
            name: "loading"
            PropertyChanges { target: main; opacity: 0 }
            PropertyChanges { target: wait; opacity: 1 }
        },
        State
        {
            name: "ready"
            PropertyChanges { target: main; opacity: 1 }
            PropertyChanges { target: wait; opacity: 0 }
        }
    ]

    /* loading */
    Loading
    {
        id: wait
        anchors.fill: parent
    }

    /* main */
    Main
    {
        id: main
        anchors.fill: parent
        Behavior on opacity { NumberAnimation { duration: 300 } }
        onMenuEntryClicked:
        {
            main.opacity = 0
            if(_id === "start_session")
                startSession.opacity = 1
            else if(_id === "register")
                register.opacity = 1
        }
    }

    StartSession
    {
        id: startSession
        anchors.fill: parent
        opacity: 0
        Behavior on opacity { NumberAnimation { duration: 300 } }
        onStartSessionClosed:
        {
            opacity = 0
            main.opacity = 1
        }
    }

    Register
    {
        id: register
        anchors.fill: parent
        opacity: 0
        Behavior on opacity { NumberAnimation { duration: 300 } }
        onRegisterClosed:
        {
            opacity = 0
            main.opacity = 1
        }
    }
}

